package com.flight.trans.http;


import android.text.TextUtils;

import com.flight.trans.BuildConfig;
import com.flight.trans.R;
import com.flight.trans.bean.ChannelBean;
import com.flight.trans.bean.CommonBean;
import com.flight.trans.bean.CommonDataBean;
import com.flight.trans.bean.CommonDoubleBean;
import com.flight.trans.bean.ContainerBean;
import com.flight.trans.bean.DamageLossBean;
import com.flight.trans.bean.DamageLossBean.DamageLossData;
import com.flight.trans.bean.LeavePorWeighingDetailsBean;
import com.flight.trans.bean.LeavePortWeightingBean;
import com.flight.trans.bean.TugBean;
import com.flight.trans.bean.DictBean;
import com.flight.trans.bean.EnterPortOrderBean;
import com.flight.trans.bean.EnterPortTakeBean;
import com.flight.trans.bean.EnterPortTakeDetailBean;
import com.flight.trans.bean.EnterPortWarehousingBean;
import com.flight.trans.bean.EnterPortWarehousingDetailBean;
import com.flight.trans.bean.FileBean;
import com.flight.trans.bean.FlightBean;
import com.flight.trans.bean.FlightSearchBean;
import com.flight.trans.bean.HandoverBean;
import com.flight.trans.bean.LeavePortCollectCheckBean;
import com.flight.trans.bean.LeavePortCollectCheckDetailBean;
import com.flight.trans.bean.LeavePortDuplicateBean;
import com.flight.trans.bean.LeavePortDuplicateDetailBean;
import com.flight.trans.bean.LeavePortGroupBoardBean;
import com.flight.trans.bean.LeavePortGroupBoardDetailBean;
import com.flight.trans.bean.LeavePortReturnBean;
import com.flight.trans.bean.LeavePortWarehousingBean;
import com.flight.trans.bean.LeavePortWarehousingDetailBean;
import com.flight.trans.bean.LoginBean;
import com.flight.trans.bean.MessageBean;
import com.flight.trans.bean.MessageReplyBean;
import com.flight.trans.bean.PageLockBean;
import com.flight.trans.bean.RouterBean;
import com.flight.trans.bean.StorageAreaBean;
import com.flight.trans.bean.StoreroomInventoryBean;
import com.flight.trans.bean.StoreroomInventoryDetailBean;
import com.flight.trans.bean.UnusualBean;
import com.flight.trans.bean.UpdateBean;
import com.flight.trans.bean.UploadFileBean;
import com.flight.trans.bean.UserBean;
import com.flight.trans.bean.WeighSectionBean;
import com.flight.trans.global.Constant;
import com.flight.trans.global.ConstantInfo;
import com.flight.trans.http.network.OkGoBackListener;
import com.flight.trans.http.network.OkGoCallBackListener;
import com.flight.trans.util.CommonUtils;
import com.flight.trans.util.JsonUtils;
import com.flight.trans.util.UploadProgressUtils;
import com.flight.trans.util.ProgressUtils;
import com.flight.trans.util.ToastUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.HttpParams;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.PostRequest;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author : YanKing
 * @date : 2021/12/11  11:49
 * @Description : 网络连接
 */
public class NetworkUtils {

    /**
     * 登录接口
     */
    public static void login(final OkGoBackListener listener,Map<String,Object> valueMap) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>post(Url.login)
                .tag(listener.getActivity())
                .upJson(new JSONObject(valueMap))
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , LoginBean.class).getData());
                    }
                });
    }

    /**
     * 登录接口
     */
    public static void logOut(final OkGoBackListener listener) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>delete(Url.logOut)
                .tag(listener.getActivity())
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(Constant.USER_NAME , ConstantInfo.USER_NAME)
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , CommonBean.class));
                    }
                });
    }

    /**
     * 消息确定参数
     */
    public static void messageReceive(final OkGoBackListener listener , String messageID , String messageType) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>get(Url.MessageReceive + "?" + Constant.ID + "=" + messageID + "&" + Constant.Type + "=" + messageType)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        ConstantInfo.MessageSocketList.remove(messageID);
                        ToastUtils.showToast(JsonUtils.parseJsonToBean(body, CommonBean.class).getMsg());
                        listener.onSuccess(body);
                    }
                });
    }

    /**
     * 消息忽略参数
     */
    public static void messageNeglect(final OkGoBackListener listener, String messageID) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>get(Url.MessageNeglect + "?" + Constant.ID + "=" + messageID + "&" + Constant.Key + "=" + ConstantInfo.SOCKET_KEY)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        ConstantInfo.MessageSocketList.remove(messageID);
                        ToastUtils.showToast(JsonUtils.parseJsonToBean(body, CommonBean.class).getMsg());
                    }
                });
    }

    /**
     * 消息列表
     */
    public static void personalMessage(final OkGoBackListener listener , int status) {

        ProgressUtils.showProgress(listener.getActivity());

        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put(Constant.State , status);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        OkGo.<String>post(Url.PersonalMessage)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .upJson(jsonObject.toString())
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , MessageBean.class).getData());
                    }
                });
    }

    /**
     * 消息详情
     */
    public static void MessageDetailsReply(final OkGoBackListener listener , String id) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>get(Url.MessageDetailsReply)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(Constant.ID , id)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        List<MessageReplyBean.MessageReplyData> messageReplyDataList = JsonUtils.parseJsonToBean(body, MessageReplyBean.class).getData();

                        String value = "" ;

                        if(messageReplyDataList != null && messageReplyDataList.size() != 0){
                            for (int i = 0; i < messageReplyDataList.size(); i++) {
                                MessageReplyBean.MessageReplyData messageReplyData = messageReplyDataList.get(i);

                                if(TextUtils.isEmpty(value)){
                                    value = messageReplyData.getName() + " [ " + messageReplyData.getDate() + " ] " + messageReplyData.getContent();
                                }else {
                                    value += "\n" + messageReplyData.getName() + " [ " + messageReplyData.getDate() + " ] " + messageReplyData.getContent();
                                }
                            }
                        }

                        listener.onSuccess(value);
                    }
                });
    }

    /**
     * 查看更新
     */
    public static void checkUpdate(final OkGoBackListener listener) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>get(Url.check_update)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(Constant.Type , BuildConfig.Type)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , UpdateBean.class).getData());
                    }
                });
    }

    /**
     * 获取用户信息接口
     */
    public static void uploadFile(final OkGoBackListener listener , File file) {

        UploadProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>post(Url.uploadFile)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(Constant.File , file)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        UploadProgressUtils.dismissProgress();

                        FileBean fileBean = JsonUtils.parseJsonToBean(body, UploadFileBean.class).getData();
                        fileBean.setFileId(fileBean.getId());
                        listener.onSuccess(fileBean);
                    }
                });
    }

    /**
     * 获取用户信息接口
     */
    public static void getUerInfo(final OkGoBackListener listener) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>get(Url.getInfo)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , UserBean.class));
                    }
                });
    }

    /**
     * 获取用户菜单
     */
    public static void getRouters(final OkGoBackListener listener) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>get(Url.getRouters)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , RouterBean.class).getData());
                    }
                });
    }

    /**
     * 航班列表
     */
    public static void getFlightList(final OkGoBackListener listener) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>post(Url.getFlightList)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .tag(listener.getActivity())
                .upJson(JsonUtils.parseBeanToJson(new FlightSearchBean()))
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , FlightBean.class).getData());
                    }
                });
    }

    /**
     * 货物安检通道列表
     */
    public static void getCheckChannel(final OkGoBackListener listener , int type) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>get(Url.getCheckChannel)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(Constant.Type , type)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , ChannelBean.class).getData());
                    }
                });
    }

    /**
     * 获取字典表数据
     */
    public static void getDictList(final OkGoBackListener listener ,String value) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>get(Url.getDictList + value)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , DictBean.class).getData());
                    }
                });
    }

    /**
     * 货物区域列表
     */
    public static void getStorageAreaList(final OkGoBackListener listener , int warehouseID) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>get(Url.getStorageAreaList)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(Constant.WarehouseID , warehouseID)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , StorageAreaBean.class).getData());
                    }
                });
    }

    /**
     * 拖斗列表
     */
    public static void getTugList(final OkGoBackListener listener , int tugType) {

        OkGoCallBackListener okGoCallBackListener = new OkGoCallBackListener(listener) {
            @Override
            public void onSuccess(String body) {
                listener.onSuccess(JsonUtils.parseJsonToBean(body, TugBean.class).getData());
            }
        };

        ProgressUtils.showProgress(listener.getActivity());

        if(tugType == 0){
            // 获取拖斗信息
            OkGo.<String>post(Url.getBroadTugList)
                    .headers(Constant.Authorization , ConstantInfo.TOKEN)
                    .tag(listener.getActivity())
                    .execute(okGoCallBackListener);
        }else {
            // 获取托盘信息
            OkGo.<String>get(Url.getBroadPalletList)
                    .headers(Constant.Authorization , ConstantInfo.TOKEN)
                    .params(Constant.Type , 1)
                    .tag(listener.getActivity())
                    .execute(okGoCallBackListener);
        }
    }

    /**
     * 集装器列表
     */
    public static void getContainerList(final OkGoBackListener listener) {

        ProgressUtils.showProgress(listener.getActivity());

        // 获取集装器信息
        OkGo.<String>post(Url.getBroadContainerList)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .upJson("{\"type\":1}")
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body, ContainerBean.class).getData());
                    }
                });
    }

    /**
     * 集装器列表
     */
    public static void getContainerAllList(final OkGoBackListener listener) {

        ProgressUtils.showProgress(listener.getActivity());

        // 获取集装器信息
        OkGo.<String>post(Url.getContainerAllList)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body, ContainerBean.class).getData());
                    }
                });
    }

    /**
     * 新增集装器
     */
    public static void addContainer(final OkGoBackListener listener , List<ContainerBean.ContainerData> valueList) {
        OkGo.<String>post(Url.addContainer)
                .headers(Constant.Authorization, ConstantInfo.TOKEN)
                .upJson(JsonUtils.parseBeanToJson(valueList))
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body, CommonBean.class));
                    }
                });
    }

    /**
     * 编辑集装器
     */
    public static void resetContainer(final OkGoBackListener listener , ContainerBean.ContainerData valueList) {
        OkGo.<String>put(Url.resetContainer)
                .headers(Constant.Authorization, ConstantInfo.TOKEN)
                .upJson(JsonUtils.parseBeanToJson(valueList))
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body, CommonBean.class));
                    }
                });
    }

    /**
     * 获取锁
     */
    public static void checkPageLock(final OkGoBackListener listener , String moduleID , String ID) {

        Map<String , String> valueMap = new HashMap<>();
        valueMap.put(Constant.ModuleID , moduleID);
        valueMap.put(Constant.Business_ID , ID);

        OkGo.<String>post(Url.checkPageLock)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .upJson(JsonUtils.parseBeanToJson(valueMap))
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        if(JsonUtils.parseJsonToBean(body , PageLockBean.class).getData()){
                            listener.onSuccess(JsonUtils.parseJsonToBean(body , PageLockBean.class).getData());
                        }else {
                            ToastUtils.showToast(R.string.toast_page_lock);
                        }
                    }
                });
    }

    /**
     * 根据地磅获取重量
     */
    public static void getBridgeWeigh(final OkGoBackListener listener , String code) {

        OkGo.<String>get(Url.getBridgeWeigh + code)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , CommonDoubleBean.class).getData());
                    }
                });
    }

    public static void checkPageLock(final OkGoBackListener listener , String moduleID , int ID) {
        checkPageLock(listener , moduleID , String.valueOf(ID));
    }

    /**
     * 获取异常列表数据
     */
    public static void getUnusualDataList(final OkGoBackListener listener,Map<String , Object> valueMap) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>post(Url.getUnusualDataList)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .upJson(JsonUtils.parseBeanToJson(valueMap))
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , UnusualBean.class).getData());
                    }
                });
    }

    /**
     * 保存异常数据
     */
    public static void saveUnusualData(final OkGoBackListener listener,String value , boolean isCreate) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGoCallBackListener okGoCallBackListener = new OkGoCallBackListener(listener) {
            @Override
            public void onSuccess(String body) {
                listener.onSuccess(JsonUtils.parseJsonToBean(body , CommonDataBean.class));
            }
        };

        if(isCreate){
            OkGo.<String>post(Url.saveUnusualData)
                    .tag(listener.getActivity())
                    .headers(Constant.Authorization , ConstantInfo.TOKEN)
                    .upJson(value)
                    .execute(okGoCallBackListener);
        }else {
            OkGo.<String>put(Url.saveUnusualData)
                    .tag(listener.getActivity())
                    .headers(Constant.Authorization , ConstantInfo.TOKEN)
                    .upJson(value)
                    .execute(okGoCallBackListener);
        }
    }

    /**
     * 删除异常数据
     */
    public static void deleteUnusual(final OkGoBackListener listener,int id) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>delete(Url.deleteUnusual + id)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , CommonBean.class));
                    }
                });
    }

    /**
     * 获取出港入库列表数据
     */
    public static void getLeavePortWarehousingList(final OkGoBackListener listener , HttpParams httpParams) {

        OkGo.<String>get(Url.getLeavePortWarehousingList)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(httpParams)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , LeavePortWarehousingBean.class).getData());
                    }
                });
    }

    /**
     * 获取出港入库相信信息
     */
    public static void getLeavePortWarehousingDetails(final OkGoBackListener listener , int ID) {

        OkGo.<String>get(Url.getLeavePortWarehousingDetails + ID)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , LeavePortWarehousingDetailBean.class).getData());
                    }
                });
    }

    /**
     * 保存出港入库信息
     */
    public static void saveLeavePortWarehousingDetails(final OkGoBackListener listener , String jsonValue) {
        ProgressUtils.showSingleProgress(listener.getActivity());

        OkGo.<String>post(Url.saveLeavePortWarehousingDetails)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .tag(listener.getActivity())
                .upJson(jsonValue)
                .execute(new OkGoCallBackListener(listener , true) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , CommonBean.class));
                    }
                });
    }

    /**
     * 获取出港组板列表数据
     */
    public static void getLeavePortGroupBoardList(final OkGoBackListener listener , Map<String , Object> valueMap) {

        OkGo.<String>post(Url.getLeavePortGroupBoardList)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .upJson(new JSONObject(valueMap))
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , LeavePortGroupBoardBean.class).getData());
                    }
                });
    }

    /**
     * 获取组板详情数据
     */
    public static void getLeavePortGroupBoardDetails(final OkGoBackListener listener , Map<String , Object> valueMap) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>post(Url.getLeavePortGroupBoardDetails)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .upJson(new JSONObject(valueMap))
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , LeavePortGroupBoardDetailBean.class).getData());
                    }
                });
    }

    /**
     * 保存组板详情数据
     */
    public static void saveLeavePortGroupBoardDetails(final OkGoBackListener listener , String jsonValue) {

        CommonUtils.writeCrashLog("出港组板保存信息:" + jsonValue);
        CommonUtils.writeCrashLog("出港组板保存网络状态:" + CommonUtils.isNetworkAvailable());

        ProgressUtils.showSingleProgress(listener.getActivity());

        OkGo.<String>post(Url.saveLeavePortGroupBoardDetails)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .upJson(jsonValue)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener , true) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , CommonBean.class));
                    }
                });
    }

    /**
     * 获取出港复重列表数据
     */
    public static void getLeavePortDuplicateList(final OkGoBackListener listener , HttpParams valueParams) {

        OkGo.<String>get(Url.getLeavePortDuplicateList)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(valueParams)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , LeavePortDuplicateBean.class).getData());
                    }
                });
    }

    /**
     * 获取复重详情数据
     */
    public static void getLeavePortDuplicateDetails(final OkGoBackListener listener , HttpParams valueParams) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>get(Url.getLeavePortDuplicateDetails)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(valueParams)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , LeavePortDuplicateDetailBean.class).getData());
                    }
                });
    }

    /**
     * 获取斗重
     */
    public static void geTransportWeight(final OkGoBackListener listener , String value) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>post(Url.getTransportWeight)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .upJson(value)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , CommonDoubleBean.class).getData());
                    }
                });
    }

    /**
     * 保存复重详情数据
     */
    public static void saveLeavePortDuplicateDetails(final OkGoBackListener listener , String jsonValue) {

        ProgressUtils.showSingleProgress(listener.getActivity());

        OkGo.<String>post(Url.saveLeavePortDuplicateDetails)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .upJson(jsonValue)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener , true) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , CommonBean.class));
                    }
                });
    }

    /**
     * 获取出港退运列表数据
     */
    public static void getLeavePortReturnList(final OkGoBackListener listener , HttpParams valueParams) {

        OkGo.<String>get(Url.getLeavePortReturnList)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(valueParams)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , LeavePortReturnBean.class).getData());
                    }
                });
    }

    /**
     * 保存退运
     */
    public static void saveLeavePortReturn(final OkGoBackListener listener , HttpParams valueParams) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>get(Url.saveLeavePortReturn)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(valueParams)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , CommonBean.class));
                    }
                });
    }

    /**
     * 获取出港核查列表数据
     */
    public static void getLeavePortCollectCheckList(final OkGoBackListener listener , HttpParams valueParams) {

        OkGo.<String>get(Url.getLeavePortCollectCheckList)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(valueParams)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , LeavePortCollectCheckBean.class).getData());
                    }
                });
    }

    /**
     * 获取出港核查详情数据
     */
    public static void getLeavePortCollectCheckDetails(final OkGoBackListener listener , HttpParams valueParams) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>get(Url.getLeavePortCollectCheckDetails)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(valueParams)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , LeavePortCollectCheckDetailBean.class).getData());
                    }
                });
    }

    /**
     * 保存核查
     */
    public static void saveLeavePortCollectCheck(final OkGoBackListener listener , String jsonValue) {

        ProgressUtils.showSingleProgress(listener.getActivity());

        CommonUtils.writeCrashLog("出港核查保存信息:" + jsonValue);
        CommonUtils.writeCrashLog("出港核查保存网络状态:" + CommonUtils.isNetworkAvailable());

        OkGo.<String>post(Url.saveLeavePortCollectCheck)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .upJson(jsonValue)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener , true) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , CommonBean.class));
                    }
                });
    }

    /**
     * 获取出港称重列表
     */
    public static void getLeavePortWeighting(final OkGoBackListener listener , HttpParams valueParams) {

        OkGo.<String>get(Url.getLeavePortWeighting)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(valueParams)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , LeavePortWeightingBean.class).getData());
                    }
                });
    }

    /**
     * 出港称重详情
     */
    public static void getLeavePortWeightingDetails(final OkGoBackListener listener , HttpParams valueParams) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>get(Url.getLeavePortWeightingDetails)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(valueParams)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , LeavePorWeighingDetailsBean.class).getData());
                    }
                });
    }

    /**
     * 出港称重保存
     */
    public static void saveLeavePortWeightingDetails(final OkGoBackListener listener , String jsonValue) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>post(Url.saveLeavePortWeightingDetails)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .upJson(jsonValue)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body, CommonBean.class));
                    }
                });
    }

    /**
     * 打印装机指示牌
     */
    public static void printInstallationSign(final OkGoBackListener listener , String params) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>post(Url.printInstallationSign)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .upJson(params)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body, CommonBean.class));
                    }
                });
    }

    /**
     * 获取进港入库列表数据
     */
    public static void getEnterPortWarehousingList(final OkGoBackListener listener , HttpParams valueParams) {

        OkGo.<String>get(Url.getEnterPortWarehousingList)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(valueParams)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , EnterPortWarehousingBean.class).getData());
                    }
                });
    }

    /**
     * 获取进港入库详情数据
     */
    public static void getEnterPortWarehousingDetails(final OkGoBackListener listener , HttpParams valueParams) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>get(Url.getEnterPortWarehousingDetails)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(valueParams)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , EnterPortWarehousingDetailBean.class).getData());
                    }
                });
    }

    /**
     * 获取进港运单详情数据
     */
    public static void getEnterPortOrderDetails(final OkGoBackListener listener , int id) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>get(Url.getEnterPortOrderDetails + id)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , EnterPortOrderBean.class).getData());
                    }
                });
    }


    /**
     * 获取事故签证
     */
    public static void getDamageLoss(final OkGoBackListener listener , int id) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>get(Url.getDamageLoss + id)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , DamageLossBean.class).getData());
                    }
                });
    }

    /**
     * 新增事故签证
     */
    public static void saveDamageLoss(final OkGoBackListener listener , DamageLossData lossData , int ID) {

        ProgressUtils.showSingleProgress(listener.getActivity());

        OkGoCallBackListener okGoCallBackListener = new OkGoCallBackListener(listener ,true) {
            @Override
            public void onSuccess(String body) {
                listener.onSuccess(JsonUtils.parseJsonToBean(body, CommonBean.class));
            }
        };

        if(ID == 0) {
            OkGo.<String>post(Url.getDamageLoss)
                    .headers(Constant.Authorization, ConstantInfo.TOKEN)
                    .upJson(JsonUtils.parseBeanToJson(lossData))
                    .tag(listener.getActivity())
                    .execute(okGoCallBackListener);
        }else {
            OkGo.<String>put(Url.getDamageLoss)
                    .headers(Constant.Authorization , ConstantInfo.TOKEN)
                    .tag(listener.getActivity())
                    .execute(okGoCallBackListener);
        }
    }

    /**
     * 保存进港入库
     */
    public static void saveEnterPortWarehousingDetails(final OkGoBackListener listener , String jsonValue) {

        CommonUtils.writeCrashLog("进港录改保存信息:" + jsonValue);
        CommonUtils.writeCrashLog("进港录改保存网络状态:" + CommonUtils.isNetworkAvailable());

        ProgressUtils.showSingleProgress(listener.getActivity());

        OkGo.<String>post(Url.saveEnterPortWarehousingDetails)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .upJson(jsonValue)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener , true) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , CommonBean.class));
                    }
                });
    }


    /**
     * 获取司机交接列表
     */
    public static void getHandoverList(final OkGoBackListener listener , int flightID , boolean isEnter) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>get(isEnter ? Url.getEnterPortHandoverList : Url.getLeavePortHandoverList)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(Constant.FlightID , flightID)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , HandoverBean.class).getData());
                    }
                });
    }

    /**
     * 保存司机交接
     */
    public static void saveHandoverDara(final OkGoBackListener listener , String jsonValue , boolean isEnter) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>post(isEnter ? Url.saveEnterPortHandoverData : Url.saveLeavePortHandoverData)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .upJson(jsonValue)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , CommonBean.class));
                    }
                });
    }

    /**
     * 获取进港出库列表数据
     */
    public static void getEnterPortPickingList(final OkGoBackListener listener , HttpParams valueParams) {

        OkGo.<String>post(Url.getEnterPortPickingList)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(valueParams)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , EnterPortTakeBean.class).getData());
                    }
                });
    }

    /**
     * 获取进港出库详情数据
     */
    public static void getEnterPortPickingDetails(final OkGoBackListener listener , HttpParams valueParams) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>get(Url.getEnterPortPickingDetails)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(valueParams)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , EnterPortTakeDetailBean.class).getData());
                    }
                });
    }

    /**
     * 保存进港出库
     */
    public static void saveEnterPortPickingDetails(final OkGoBackListener listener , String jsonValue) {

        ProgressUtils.showSingleProgress(listener.getActivity());

        OkGo.<String>post(Url.saveEnterPortPickingDetails)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .upJson(jsonValue)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener , true) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , CommonBean.class));
                    }
                });
    }

    /**
     * 获取进港入库列表数据
     */
    public static void getEnterPortTakeList(final OkGoBackListener listener , HttpParams valueParams) {

        OkGo.<String>post(Url.getEnterPortTakeList)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(valueParams)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , EnterPortTakeBean.class).getData());
                    }
                });
    }

    /**
     * 获取进港入库详情数据
     */
    public static void getEnterPortTakeDetails(final OkGoBackListener listener , HttpParams valueParams) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>get(Url.getEnterPortTakeDetails)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(valueParams)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , EnterPortTakeDetailBean.class).getData());
                    }
                });
    }

    /**
     * 进港分配提货通道保存
     */
    public static void saveEnterPortChannel(final OkGoBackListener listener , HttpParams httpParams) {

        ProgressUtils.showSingleProgress(listener.getActivity());

        OkGo.<String>get(Url.saveEnterPortChannel)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(httpParams)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener , true) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , CommonBean.class));
                    }
                });
    }

    /**
     * 保存进港入库
     */
    public static void saveEnterPortTakeDetails(final OkGoBackListener listener , String jsonValue) {

        ProgressUtils.showSingleProgress(listener.getActivity());

        OkGo.<String>post(Url.saveEnterPortTakeDetails)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .upJson(jsonValue)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener , true) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , CommonBean.class));
                    }
                });
    }

    /**
     * 获取盘库列表数据
     */
    public static void getStoreroomInventoryList(final OkGoBackListener listener , HttpParams valueParams , boolean isEnter) {

        OkGo.<String>get(isEnter ? Url.getEnterStoreroomInventoryList : Url.getLeaveStoreroomInventoryList)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(valueParams)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , StoreroomInventoryBean.class).getData());
                    }
                });
    }

    /**
     * 获取盘库列表数据
     */
    public static void getStoreroomInventoryDetail(final OkGoBackListener listener , int storageCheckId , boolean isEnter) {

        ProgressUtils.showSingleProgress(listener.getActivity());

        String enterUrl =  storageCheckId == -1 ? Url.getEnterStoreroomInventoryNew : Url.getEnterStoreroomInventoryDetail;
        String leaveUrl =  storageCheckId == -1 ? Url.getLeaveStoreroomInventoryNew : Url.getLeaveStoreroomInventoryDetail;

        OkGo.<String>get(isEnter ? enterUrl : leaveUrl)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .params(Constant.Key_Storage_Check_ID , storageCheckId)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener , true) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , StoreroomInventoryDetailBean.class).getData());
                    }
                });
    }

    /**
     * 保存进港盘库
     */
    public static void saveStoreroomInventoryData(final OkGoBackListener listener , String jsonValue , boolean isEnter) {

        ProgressUtils.showSingleProgress(listener.getActivity());

        CommonUtils.writeCrashLog("盘库信息保存信息:" + jsonValue);
        CommonUtils.writeCrashLog("盘库信息保存网络状态:" + CommonUtils.isNetworkAvailable());

        OkGo.<String>post(isEnter ? Url.saveEnterStoreroomInventoryData : Url.saveLeaveStoreroomInventoryData)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .upJson(jsonValue)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener , true) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , CommonBean.class));
                    }
                });
    }

    /**
     * 获取复重区间集合
     */
    public static void getWeighSectionList(final OkGoBackListener listener) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>get(Url.getWeighSectionList)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , WeighSectionBean.class).getData());
                    }
                });
    }

    /**
     * 进港出库
     */
    public static void updateOrderToOut(final OkGoBackListener listener , int id , int turnType) {

        ProgressUtils.showProgress(listener.getActivity());

        OkGo.<String>get((turnType == 0 ? Url.inWardUpdateOrderToOut : Url.outWardUpdateOrderToOut) + id)
                .headers(Constant.Authorization , ConstantInfo.TOKEN)
                .tag(listener.getActivity())
                .execute(new OkGoCallBackListener(listener) {
                    @Override
                    public void onSuccess(String body) {
                        listener.onSuccess(JsonUtils.parseJsonToBean(body , CommonBean.class));
                    }
                });
    }
}